<?php 

	include("includes/connect_db.php"); 

	$searchKey = $_POST['key'];
	switch ($_GET["act"]) {
		case 1:
			$sql = "SELECT * FROM 
                        (SELECT 
                            c.id_kontak AS id,
                            c.nama_rincian AS nama,
                            'Kontak' AS tipe
                        FROM
                            tb_kontak_rincian c
                        UNION
                        SELECT 
                            d.id_group AS id, 
                            d.nama_group AS nama, 
                            'group' AS tipe 
                        FROM tb_group_kontak d)
                    AS 
                        tb_kontak_gabung
                    WHERE nama 
                    LIKE '%".$searchKey."%'";
                 
            $sql .= " ORDER BY nama ASC LIMIT 5";
            $query = mysql_query($sql);
            while ($baris = mysql_fetch_array($query)) {
              $data[] = array("id"=>$baris['id'],"nama"=>$baris['nama'],"tipe"=>$baris["tipe"]);
            }
            echo json_encode($data);
            break;
	}

?>